﻿using System;
using FPP.Models;
using NUnit.Framework;

namespace FPP.Tests.Models
{
    [TestFixture]
    public class FamousPersonTest: BaseTest
    {
        [TestFixtureSetUp]
        public void FamousPersonSetup()
        {
            var fp = new FamousPerson()
            {
                Id = 1,
                DisplayName = "Brad Pitt",
                DateOfBirth = new DateTime(1963, 12, 8),
                DateOfDeath = new DateTime(),
                WikiLink = "http://en.wikipedia.org/wiki/Brad_Pitt"
            };
            var fp2 = new FamousPerson()
            {
                Id = 2,
                DisplayName = "Brad Pitt",
                DateOfBirth = new DateTime(1963, 12, 8),
                DateOfDeath = new DateTime(),
                WikiLink = "http://en.wikipedia.org/wiki/Brad_Pitt2"
            };

            _context = new FakeFppEntities();

            var repository = new FppRepository(_context);

            repository.AddFamousPerson(fp);
            repository.AddFamousPerson(fp2);

            repository.SaveChanges();

        }

        [Test]
        public void ShouldReturnAListofFamousPeople()
        {
            var repository = new FppRepository(_context);

            var testthis = repository.GetListOfFamousPersons();
            
            Assert.Greater(testthis.Count, 0);
        }

        [Test]
        public void PreventTwoFamousPeopleWithTheSameWikiLink()
        {
            var repository = new FppRepository(_context);

            var fp = new FamousPerson()
            {
                Id = 1,
                DisplayName = "Another Pitt",
                DateOfBirth = new DateTime(1963, 12, 8),
                DateOfDeath = new DateTime(),
                WikiLink = "http://en.wikipedia.org/wiki/Brad_Pitt"
            };

            repository.AddFamousPerson(fp);

            repository.SaveChanges();

            Assert.IsFalse(repository.GetListOfFamousPersons().Contains(fp));
        }
    }
}
